//
//  PaySuccessfulViewController.m
//  Youhuiju
//
//  Created by 余尚飞 on 16/8/12.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "PaySuccessfulViewController.h"
#import "GoodsDetailViewController.h"
#import "ViewOrderViewController.h"
//自定义视图
#import "PaySuccessfulTopView.h"

//自定义cell
#import "PaySuccessfulTableViewCell.h"
#import "YouLovedTableViewCell.h"

@interface PaySuccessfulViewController ()<UITableViewDelegate,UITableViewDataSource,cellClickedDelegate,cellButtonClickedDelegate>

@property(nonatomic,strong)PaySuccessfulTopView *topView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation PaySuccessfulViewController

static NSString *PaySuccessfulTableViewCellIden = @"PaySuccessfulTableViewCellIden";
static NSString *YouLovedTableViewCellIden = @"YouLovedTableViewCellIden";


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self load_UI];
    
    
    
    // Do any additional setup after loading the view from its nib.
}

#pragma mark ----- load_UI
-(void)load_UI
{
    [self topView];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"PaySuccessfulTableViewCell" bundle:nil] forCellReuseIdentifier:PaySuccessfulTableViewCellIden];
    [self.tableView registerNib:[UINib nibWithNibName:@"YouLovedTableViewCell" bundle:nil] forCellReuseIdentifier:YouLovedTableViewCellIden];
    
}

#pragma mark ------- tableView delegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        return 228 * FitH;
    }
    else
    {
        return 420 * FitH;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 1)
    {
        return 10 * FitH;
    }
    else
    {
        return 0;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WeakObj(self);
    if (indexPath.section == 0)
    {
        PaySuccessfulTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PaySuccessfulTableViewCellIden forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.buttonClickedHandler = ^(NSInteger buttonTag){
            
            if (buttonTag == 0)
            {
                DLog(@"查看订单");
                ViewOrderViewController *vc = [[ViewOrderViewController alloc] initWithNibName:@"ViewOrderViewController" bundle:nil];
                vc.model = weakself.model;
                [self.navigationController pushViewController:vc animated:YES];
                
            }
            else
            {
                [weakself.navigationController popToRootViewControllerAnimated:YES];
            }
            
        };
        return cell;
    }
    else
    {
        YouLovedTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:YouLovedTableViewCellIden forIndexPath:indexPath];
        cell.cellDelegate = self;
        cell.cellButtonDelegate = self;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }
}

#pragma mark ------ private delegate
//猜你喜欢按钮点击协议
-(void)cellButtonClickedJump:(NSInteger)buttonTag
{
    if (buttonTag == 0)
    {
//        GoodsDetailViewController  *DVC = [[GoodsDetailViewController alloc]initWithNibName:@"GoodsDetailViewController" bundle:nil];
//        self.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:DVC animated:YES];
//        self.hidesBottomBarWhenPushed = NO;
        DLog(@"这是加入购物车button");
    }
    else
    {
        GoodsDetailViewController  *DVC = [[GoodsDetailViewController alloc]initWithNibName:@"GoodsDetailViewController" bundle:nil];
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:DVC animated:YES];
        self.hidesBottomBarWhenPushed = NO;
        DLog(@"这是进入分类button");
    }
}

//猜你喜欢cell点击协议
-(void)cellClickedJump
{
    DLog(@"你点击了cell");
    GoodsDetailViewController  *DVC = [[GoodsDetailViewController alloc]initWithNibName:@"GoodsDetailViewController" bundle:nil];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:DVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}




#pragma mark ------- lazy loading
-(PaySuccessfulTopView *)topView
{
    WeakObj(self);
    if (!_topView)
    {
        _topView = [[PaySuccessfulTopView alloc]init];
        [self.view addSubview:_topView];
        [_topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left);
            make.right.equalTo(self.view.mas_right);
            make.top.equalTo(self.view.mas_top).offset(20);
            make.height.equalTo(@44);
        }];
        _topView.backButtonClickedHandler = ^{
            
            [weakself.navigationController popToRootViewControllerAnimated:YES];
        };
    }
        return _topView;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
